FIND_PACKAGE(Ruby REQUIRED)
FIND_PACKAGE(RubyNArray REQUIRED)
SET(NARRAY_LIB ${RUBY_NARRAY_LIBRARY} PARENT_SCOPE)
UNSET(TARGET_SWIGFLAGS)

include(ShogunInterfaces)
INCLUDE_DIRECTORIES(${RUBY_INCLUDE_DIRS} ${RUBY_NARRAY_INCLUDE_DIR})

CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/shogun.rb.in"
		"${CMAKE_CURRENT_BINARY_DIR}/shogun.rb" @ONLY)

GENERATE_INTERFACE_TARGET(ruby ${CMAKE_CURRENT_SOURCE_DIR} ${RUBY_LIBRARY})
set_target_properties(interface_ruby PROPERTIES PREFIX "")
target_compile_definitions(interface_ruby PRIVATE NARRAY_LIB="${RUBY_NARRAY_LIBRARY}")

SET(INTERFACE_RUBY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)

EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['sitearchdir']"
		OUTPUT_VARIABLE RUBY_SITE_ARCH_DIR
		ERROR_QUIET)

INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/shogun.rb
	DESTINATION ${RUBY_SITE_ARCH_DIR}
	COMPONENT ruby)

INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/shogun.so
	DESTINATION ${RUBY_SITE_ARCH_DIR}
	COMPONENT ruby
	RENAME shogun${EXT_LIB_SWIG_RUBY})
